﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using System.Net;
using ServerPicture.Models;

namespace ServerPicture
{
    public partial class index : System.Web.UI.Page
    {

        protected void Button1_Click(object sender, EventArgs e)
        {
          
            IEnumerable<Photo> _post = getdata(50,3,3);
            using(DatabaseDataContext dc = new DatabaseDataContext())
            {
                dc.Photos.InsertAllOnSubmit(_post);
                dc.SubmitChanges();
            }                               
        }
        public List<Photo> getdata(int soluong,int cateid,int tagid )
        {
             DatabaseDataContext dc = new DatabaseDataContext();
             var list = (from p in dc.Photos orderby p.Photo_ID descending select p).Take(1).ToList();
             int idlast=0;
             foreach(Photo pt in list)
             {
                 idlast=Convert.ToInt32(pt.Photo_ID);
             }
             List<Photo> lst = new List<Photo>();
             for(int i=idlast+1;i<idlast+soluong;i++)
             {
                 Photo photo = new Photo();
                 photo.Cate_ID=cateid;
                 photo.Photo_Description="Anh testing";
                 photo.Photo_DateAdd=null;
                 photo.Photo_DateUpdate = null;
                 photo.URL = "https://lh5.ggpht.com/FBdj7X3_egZYJTWiHoh1sXFWCZ0DaUWRJ34hUqkawHb8vivB59M9Vzsi5nnxqdXO7qRMS1nhZfdx5UjQMUtcEOOu7hug_rqpYsT5KcJtSA";
                
                 lst.Add(photo);
             }
             return lst;
        }
    }
}